/**
 * Created by CK on 2017/5/4.
 */
$(document).ready(function(){
    var formDom = $('#form_exam');
    $('#send').click(function(){
        var data = {};
        $.each(formDom.serializeArray(), function() {
            data[this.name] = this.value;
        });
        if(!data.examId){
            showMsg('题库ID不能为空！');
            return false;
        }
        window.top.swal({
            titleText: '接收结果邮箱地址',
            input: 'email',
            inputPlaceholder: 'xxx@100fen.cn',
            inputAttributes: {style: 'max-width:200px;'},
            showCancelButton: true,
            cancelButtonText: '取消',
            confirmButtonText: '确认',
            showLoaderOnConfirm: true,
            allowOutsideClick: false,
            preConfirm: function (address) {
                return new Promise(function (resolve, reject) {
                    data.address = address;
                    $.ajax({
                        url: formDom.attr('action'),
                        type: 'POST',
                        timeout: 2000,
                        //async: false,
                        data: data,
                        success: function(data){
                            showMsg(data);
                        },
                        error: function(){
                            showMsg('成功！稍后请查看邮件获取结果。', 'success');
                        }
                    });
                })
            }
        }).then(function (address) {
        }, function(dismiss) {});
    });
    function showMsg(msg, type){
        if(!type) type = 'error';
        window.top.xhTop.showMessage({title:msg, type:type});
    }
});